<?
/*
Bitsand - a web-based booking system for LRP events
Copyright (C) 2006, 2007 Russell Peter Phillips

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/
include ('inc_head_db.php');
include ('inc_head_html.php');
include ('inc_admin.php');
?>

<h1><?=TITLE?> - View Details</h1>

<p><a href = "admin.php">Admin</a></p>

<?
//Player ID is passed as GET. Should be an integer, so cast to integer
$pid = (int) $_GET ['pid'];
if ($pid != 0) {
	echo "<h2>Player ID " . PID_PREFIX . sprintf ('%03s', $pid) . "</h2>\n";
	//Get OOC details
	$sql = "SELECT AES_DECRYPT(plFirstName, '$key') AS dFirstName, " .
		"AES_DECRYPT(plSurname, '$key') AS dSurname, " .
		"AES_DECRYPT(plAddress1, '$key') AS dAddress1, " .
		"AES_DECRYPT(plAddress2, '$key') AS dAddress2, " .
		"AES_DECRYPT(plAddress3, '$key') AS dAddress3, " .
		"AES_DECRYPT(plAddress4, '$key') AS dAddress4, " .
		"AES_DECRYPT(plPostcode, '$key') AS dPostcode, " .
		"AES_DECRYPT(plTelephone, '$key') AS dTelephone, " .
		"AES_DECRYPT(plMobile, '$key') AS dMobile, " .
		"AES_DECRYPT(plEmail, '$key') AS dEmail, " .
		"AES_DECRYPT(plDOB, '$key') AS dDOB, " .
		"AES_DECRYPT(plMedicalInfo, '$key') AS dMedicalInfo, " .
		"AES_DECRYPT(plEmergencyName, '$key') AS dEmergencyName, " .
		"AES_DECRYPT(plEmergencyNumber, '$key') AS dEmergencyNumber, " .
		"AES_DECRYPT(plEmergencyRelationship, '$key') AS dEmergencyRelationship, " .
		"AES_DECRYPT(plCarRegistration, '$key') AS dCarRegistration, " .
		"AES_DECRYPT(plDietary, '$key') AS dDietary " .
		"FROM players " .
		"WHERE plPlayerID = $pid";
	$result = mysqli_query ($link, $sql);
	while ($row = mysqli_fetch_assoc ($result)){

	echo "<h3>OOC Details</h3>\n";
	echo "<table border = '0'>\n";
	echo "<tr class = 'highlight'><td>Name:</td><td>" . htmlentities (stripslashes ($row ['dFirstName'])) . " " .
		htmlentities (stripslashes ($row ['dSurname'])) . "</td></tr>\n";
	echo "<tr class = 'highlight'><td>Address:</td><td>" . htmlentities (stripslashes ($row ['dAddress1'])) . ", " .
		htmlentities (stripslashes ($row ['dAddress2'])) . ", " . htmlentities (stripslashes ($row ['dAddress3'])) . ", " .
		htmlentities (stripslashes ($row ['dAddress4'])) . ", " . htmlentities (stripslashes ($row ['dPostcode'])) . "</td></tr>\n";
	echo "<tr class = 'highlight'><td>Telephone:</td><td>" . htmlentities (stripslashes ($row ['dTelephone'])) . "</td></tr>\n";
	echo "<tr class = 'highlight'><td>Mobile:</td><td>" . htmlentities (stripslashes ($row ['dMobile'])) . "</td></tr>\n";
	//Date of birth is stored in YYYYMMDD format - need to decode
	$sDoB = $row ['dDOB'];
	$iDobYear = substr ($sDoB, 0, 4);
	$iMonth = substr ($sDoB, 4, 2);
	$iDate = substr ($sDoB, 6, 2);
	echo "<tr class = 'highlight'><td>Date of Birth:</td><td>$iDate-$iMonth-$iDobYear</td></tr>\n";
	echo "<tr class = 'highlight'><td>Medial Info:</td><td>" . htmlentities (stripslashes ($row ['dMedicalInfo'])) . "</td></tr>\n";
	echo "<tr class = 'highlight'><td>Emergency Contact:</td><td>" . htmlentities (stripslashes ($row ['dEmergencyName'])) . "</td></tr>\n";
	echo "<tr class = 'highlight'><td>Emergency Contact (number):</td><td>" .
		htmlentities (stripslashes ($row ['dEmergencyNumber'])) . "</td></tr>\n";
	echo "<tr class = 'highlight'><td>Emergency Contact (relationship):</td><td>" .
		htmlentities (stripslashes ($row ['dEmergencyRelationship'])) . "</td></tr>\n";
	echo "<tr class = 'highlight'><td>Car Registration:</td><td>" . htmlentities (stripslashes ($row ['dCarRegistration'])) . "</td></tr>\n";
	echo "<tr class = 'highlight'><td>Dietary Requirements:</td><td>" . htmlentities (stripslashes ($row ['dDietary'])) . "</td></tr>\n";
	echo "</table>\n";
	
	echo "<h3>IC Details</h3>";
	$sql = "SELECT * FROM characters WHERE chPlayerID = $pid";
	$result = mysqli_query ($link, $sql);
	$row = mysqli_fetch_assoc ($result);
	$sNotes = $row ['chNotes'];
	$sOSP = $row ['chOSP'];
	?>
	<table><tr class = 'highlight'>
	<td>Character Name:</td>
	<td><?=htmlentities (stripslashes ($row ['chName']))?></td>
	</tr><tr class = 'highlight'>
	<td>Race &amp; Gender:</td>
	<td><?=htmlentities (stripslashes ($row ['chRace']))?>, <?=htmlentities (stripslashes ($row ['chGender']))?></td>
	</tr><tr class = 'highlight'>
	<td>Group:</td>
	<td>
	<?
	if ($row ['chGroupSel'] == ' Other (enter name below)')
		$sGroup = htmlentities (stripslashes ($row ['chGroupText']));
	else
		$sGroup = htmlentities (stripslashes ($row ['chGroupSel']));
	echo $sGroup;
	?>
	</td>
	</tr><tr class = 'highlight'>
	<td>Faction and Rank:</td>
	<td><?=htmlentities (stripslashes ($row ['chFaction']))?>, Rank <?=htmlentities (stripslashes ($row ['chFactionRank']))?></td>
	</tr><tr class = 'highlight'>
	<td>Guild(s) &amp; Rank(s):</td>
	<td><?=htmlentities (stripslashes ($row ['chGuilds']))?></td>
	</tr><tr class = 'highlight'>
	<td>Ancestor:</td><td><?=htmlentities (stripslashes ($row ['chAncestor']))?></td>
	</tr><tr class = 'highlight'>
	<td>Isle of usual residence:</td>
	<td><?=htmlentities (stripslashes ($row ['chIsle']))?></td>
	</tr><tr class = 'highlight'>
	<td>NPC Status:</td>
	<td>
	<?
	if ($row ['chNPC'] == '1')
		echo "NPC";
	else
		echo "Not an NPC";
	echo "</td></tr>\n";
	}
	echo "<tr><td colspan = '2'>&nbsp;</td></tr>\n";
	echo "<th>Skill</th><th>Points</th>\n";
	$sql = "SELECT * FROM skills, skillstaken WHERE skID = stSkillID AND stPlayerID = $pid";
	$result = mysqli_query ($link, $sql);
	while ($row = mysqli_fetch_assoc ($result))
		echo "<tr class = 'highlight'><td>" . $row ['skName'] . "</td><td>" . $row ['stPoints'] . "</td></tr>\n";
	?>
	<tr><td colspan = "2">&nbsp;</td></tr>
	<tr><td colspan = '2'><b>Notes</b><br>
	<?
	$sNotes = htmlentities (stripslashes ($sNotes));
	if ($sNotes == '')
		echo "<i>None</i>\n";
	else
		echo str_replace ("\n", "<br>", $sNotes);
	?>
	</td></tr>

	<tr><td colspan = "2">&nbsp;</td></tr>
	<tr><td colspan = '2'><b>OSPs, special items/powers/creatures:</b></td></tr>
	<tr><td colspan = '2'>
	<?
	$sOSP = htmlentities (stripslashes ($sOSP));
	if ($sOSP == '')
		echo "<i>None</i>\n";
	else
		echo str_replace ("\n", "<br>", $sOSP);
	echo "</td></tr>\n";
	echo "</table>\n";
}
?>


<?
include ('inc_foot.php');
?>
